package com.extrace;

import android.content.Context;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.extrace.model.PackageHistory;

import java.util.List;

public class ExHistoryListAdapter extends ArrayAdapter<PackageHistory> {
    private final int resourceId;


    public ExHistoryListAdapter(@NonNull Context context, int resource, @NonNull List<PackageHistory> objects) {
        super(context, resource, objects);
        resourceId = resource;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        PackageHistory ph = (PackageHistory) getItem(position);
        View view = LayoutInflater.from(getContext()).inflate(resourceId, null);
        TextView time = (TextView) view.findViewById(R.id.time);
        TextView pkAction = (TextView) view.findViewById(R.id.pkAction);
        TextView status = (TextView) view.findViewById(R.id.status);
        time.setText(DateFormat.format("yyyy年MM月dd日 HH:mm:ss",ph.getTime()));
        pkAction.setText(ph.getPkAction());
        status.setText(ph.getStatus());
        return view;
    }
}
